//
//  MyUtil.m
//
//  Copyright © 2016年 apple. All rights reserved.
//

#import "MyUtil.h"

@implementation MyUtil

+ (UITextField *)createTextFiledFrame:(CGRect)frame placeHolder:(NSString *)placeHolder{
    
    UITextField * textFiled =[[UITextField alloc]initWithFrame:frame];
    textFiled.placeholder=placeHolder;
    //圆角
    textFiled.borderStyle=UITextBorderStyleRoundedRect;
    return textFiled;
}


+ (UILabel *)createLabelFrame:(CGRect)frame title:(NSString *)title textColor:(UIColor *)color textAlignment:(NSTextAlignment)textAlignment font:(UIFont *)font
{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    if (title.length>0) {
         label.text = title;
    }
    label.textColor = color;
    label.textAlignment = textAlignment;
    label.font = font;
    return label;
}

+ (UIButton *)createBtnFrame:(CGRect)frame title:(NSString *)title bgImage:(NSString *)bgImageName selectBgImage:(NSString *)selectImageName image:(NSString *)imageName target:(id)target action:(SEL)action
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    [btn setTitle:title forState:UIControlStateNormal];
    //字体颜色修改为黑色
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    if (imageName) {
        [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    }
    if (bgImageName) {
        [btn setBackgroundImage:[UIImage imageNamed:bgImageName] forState:UIControlStateNormal];
        
        [btn setBackgroundImage:[UIImage imageNamed:bgImageName] forState:UIControlStateHighlighted];
    }
    
    //选中图片
    if (selectImageName) {
//        [btn setBackgroundImage:[UIImage imageNamed:selectImageName] forState:UIControlStateSelected];
        [btn setImage:[UIImage imageNamed:selectImageName] forState:UIControlStateSelected];
    }

    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return btn;
}

+ (UIImageView *)createImageViewFrame:(CGRect)frame imageName:(NSString *)imageName
{
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:frame];
    if (imageName.length>0) {
         imgView.image = [UIImage imageNamed:imageName];
    }
   
    return imgView;
}


@end
